﻿Imports System.Text
Namespace TransactionSales
    Public Class clsview_SalesInputRow
        Inherits ADODBU.RowClass
        Private mVar_BARCODE As System.String
        Private mVar_SIZE As System.String
        Private mVar_COLOR As System.String
        Private mVar_BARDESCR As System.String
        Private mVar_SLSQTY As System.Int32
        Private mVar_DISCACRAMOUNT As System.Decimal
        Private mVar_SLSTOTAMT As System.Decimal
        Private mVar_SLSPRICE As System.Decimal
        Private mVar_SLSDISC As System.String
        Private mVar_DirtyBARCODE As Boolean = False
        Private mVar_DirtySIZE As Boolean = False
        Private mVar_DirtyCOLOR As Boolean = False
        Private mVar_DirtyBARDESCR As Boolean = False
        Private mVar_DirtySLSQTY As Boolean = False
        Private mVar_DirtyDISCACRAMOUNT As Boolean = False
        Private mVar_DirtySLSTOTAMT As Boolean = False
        Private mVar_DirtySLSPRICE As Boolean = False
        Private mVar_DirtySLSDISC As Boolean = False
        Private mIsOnInit As Boolean
        Public DataSource As ADODBU.Recordset
        Public RowOrigin As clsview_SalesInputRow
        ''[------------------------------------------------------------------------]'
        Public Sub New()
            RowOrigin = New clsview_SalesInputRow(True)
        End Sub
        ''[------------------------------------------------------------------------]'
        Friend Sub New(lCut As Boolean)
            '--- untuk memutus loop reference 
        End Sub
        ''[------------------------------------------------------------------------]'
        ''' <summary>
        ''' create new this class from inherited of this class or its self
        ''' </summary>
        ''' <param name="recdataRow"></param>
        ''' <remarks></remarks>
        Public Sub New(ByVal recdataRow As ADODBU.RowClass)
            RowOrigin = New clsview_SalesInputRow(True)
            Me.JoinValue(recdataRow)
        End Sub
        ''[------------------------------------------------------------------------]'
        Public Sub New(recData As ADODBU.Recordset)
            RowOrigin = New clsview_SalesInputRow(True)
            DataSource = recData
            Try
                InitVar(recData.GetCurrentDataRow)
            Catch
            End Try
        End Sub

        ''[------------------------------------------------------------------------]'
        Public Sub New(recdataRow As DataRow)
            RowOrigin = New clsview_SalesInputRow(True)
            InitVar(recdataRow)
        End Sub

#Region "Initialize vars "
        ''[------------------------------------------------------------------------]'
        Private Sub InitVar(Fields As DataRow)
            Try
                mVar_BARCODE = Fields("BARCODE")
                RowOrigin.BARCODE = mVar_BARCODE
            Catch e As Exception
            End Try
            Try
                mVar_SIZE = Fields("SIZE")
                RowOrigin.SIZE = mVar_SIZE
            Catch e As Exception
            End Try
            Try
                mVar_COLOR = Fields("COLOR")
                RowOrigin.COLOR = mVar_COLOR
            Catch e As Exception
            End Try
            Try
                mVar_BARDESCR = Fields("BARDESCR")
                RowOrigin.BARDESCR = mVar_BARDESCR
            Catch e As Exception
            End Try
            Try
                mVar_SLSQTY = Fields("SLSQTY")
                RowOrigin.SLSQTY = mVar_SLSQTY
            Catch e As Exception
            End Try
            Try
                mVar_DISCACRAMOUNT = Fields("DISCACRAMOUNT")
                RowOrigin.DISCACRAMOUNT = mVar_DISCACRAMOUNT
            Catch e As Exception
            End Try
            Try
                mVar_SLSTOTAMT = Fields("SLSTOTAMT")
                RowOrigin.SLSTOTAMT = mVar_SLSTOTAMT
            Catch e As Exception
            End Try
            Try
                mVar_SLSPRICE = Fields("SLSPRICE")
                RowOrigin.SLSPRICE = mVar_SLSPRICE
            Catch e As Exception
            End Try
            Try
                mVar_SLSDISC = Fields("SLSDISC")
                RowOrigin.SLSDISC = mVar_SLSDISC
            Catch e As Exception
            End Try
        End Sub


#End Region
        ''[------------------------------------------------------------------------]'
#Region "Properties"
        Public Property BARCODE As System.String
            Get
                Return mVar_BARCODE
            End Get
            Set(ByVal Value As System.String)
                mVar_BARCODE = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("BARCODE"))
                If Not mIsOnInit Then
                    mVar_DirtyBARCODE = True
                End If
            End Set
        End Property
        Public Property SIZE As System.String
            Get
                Return mVar_SIZE
            End Get
            Set(ByVal Value As System.String)
                mVar_SIZE = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("SIZE"))
                If Not mIsOnInit Then
                    mVar_DirtySIZE = True
                End If
            End Set
        End Property
        Public Property COLOR As System.String
            Get
                Return mVar_COLOR
            End Get
            Set(ByVal Value As System.String)
                mVar_COLOR = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("COLOR"))
                If Not mIsOnInit Then
                    mVar_DirtyCOLOR = True
                End If
            End Set
        End Property
        Public Property BARDESCR As System.String
            Get
                Return mVar_BARDESCR
            End Get
            Set(ByVal Value As System.String)
                mVar_BARDESCR = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("BARDESCR"))
                If Not mIsOnInit Then
                    mVar_DirtyBARDESCR = True
                End If
            End Set
        End Property
        Public Property SLSQTY As System.Int32
            Get
                Return mVar_SLSQTY
            End Get
            Set(ByVal Value As System.Int32)
                mVar_SLSQTY = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("SLSQTY"))
                If Not mIsOnInit Then
                    mVar_DirtySLSQTY = True
                End If
            End Set
        End Property
        Public Property DISCACRAMOUNT As System.Decimal
            Get
                Return mVar_DISCACRAMOUNT
            End Get
            Set(ByVal Value As System.Decimal)
                mVar_DISCACRAMOUNT = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("DISCACRAMOUNT"))
                If Not mIsOnInit Then
                    mVar_DirtyDISCACRAMOUNT = True
                End If
            End Set
        End Property
        Public Property SLSTOTAMT As System.Decimal
            Get
                Return mVar_SLSTOTAMT
            End Get
            Set(ByVal Value As System.Decimal)
                mVar_SLSTOTAMT = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("SLSTOTAMT"))
                If Not mIsOnInit Then
                    mVar_DirtySLSTOTAMT = True
                End If
            End Set
        End Property
        Public Property SLSPRICE As System.Decimal
            Get
                Return mVar_SLSPRICE
            End Get
            Set(ByVal Value As System.Decimal)
                mVar_SLSPRICE = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("SLSPRICE"))
                If Not mIsOnInit Then
                    mVar_DirtySLSPRICE = True
                End If
            End Set
        End Property
        Public Property SLSDISC As System.String
            Get
                Return mVar_SLSDISC
            End Get
            Set(ByVal Value As System.String)
                mVar_SLSDISC = Value
                Me.OnPropertyChanged(New System.ComponentModel.PropertyChangedEventArgs("SLSDISC"))
                If Not mIsOnInit Then
                    mVar_DirtySLSDISC = True
                End If
            End Set
        End Property
        Public ReadOnly Property BARCODEIsDirty As Boolean
            Get
                Return mVar_DirtyBARCODE
            End Get
        End Property
        Public ReadOnly Property SIZEIsDirty As Boolean
            Get
                Return mVar_DirtySIZE
            End Get
        End Property
        Public ReadOnly Property COLORIsDirty As Boolean
            Get
                Return mVar_DirtyCOLOR
            End Get
        End Property
        Public ReadOnly Property BARDESCRIsDirty As Boolean
            Get
                Return mVar_DirtyBARDESCR
            End Get
        End Property
        Public ReadOnly Property SLSQTYIsDirty As Boolean
            Get
                Return mVar_DirtySLSQTY
            End Get
        End Property
        Public ReadOnly Property DISCACRAMOUNTIsDirty As Boolean
            Get
                Return mVar_DirtyDISCACRAMOUNT
            End Get
        End Property
        Public ReadOnly Property SLSTOTAMTIsDirty As Boolean
            Get
                Return mVar_DirtySLSTOTAMT
            End Get
        End Property
        Public ReadOnly Property SLSPRICEIsDirty As Boolean
            Get
                Return mVar_DirtySLSPRICE
            End Get
        End Property
        Public ReadOnly Property SLSDISCIsDirty As Boolean
            Get
                Return mVar_DirtySLSDISC
            End Get
        End Property
#End Region
        ''[------------------------------------------------------------------------]'
        Public Function SaveToDataSource() As String
            Dim msgErr As String
            msgErr = ""
            If mVar_DirtyBARCODE Then
                Try
                    DataSource.Fields("BARCODE") = mVar_BARCODE
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            If mVar_DirtySIZE Then
                Try
                    DataSource.Fields("SIZE") = mVar_SIZE
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            If mVar_DirtyCOLOR Then
                Try
                    DataSource.Fields("COLOR") = mVar_COLOR
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            If mVar_DirtyBARDESCR Then
                Try
                    DataSource.Fields("BARDESCR") = mVar_BARDESCR
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            If mVar_DirtySLSQTY Then
                Try
                    DataSource.Fields("SLSQTY") = mVar_SLSQTY
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            If mVar_DirtyDISCACRAMOUNT Then
                Try
                    DataSource.Fields("DISCACRAMOUNT") = mVar_DISCACRAMOUNT
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            If mVar_DirtySLSTOTAMT Then
                Try
                    DataSource.Fields("SLSTOTAMT") = mVar_SLSTOTAMT
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            If mVar_DirtySLSPRICE Then
                Try
                    DataSource.Fields("SLSPRICE") = mVar_SLSPRICE
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            If mVar_DirtySLSDISC Then
                Try
                    DataSource.Fields("SLSDISC") = mVar_SLSDISC
                Catch e As Exception
                    msgErr = msgErr & e.Message
                End Try
            End If

            Return msgErr
        End Function

        ''[------------------------------------------------------------------------]'
        Public Sub ClearDirty()
            mVar_DirtyBARCODE = False
            mVar_DirtySIZE = False
            mVar_DirtyCOLOR = False
            mVar_DirtyBARDESCR = False
            mVar_DirtySLSQTY = False
            mVar_DirtyDISCACRAMOUNT = False
            mVar_DirtySLSTOTAMT = False
            mVar_DirtySLSPRICE = False
            mVar_DirtySLSDISC = False
        End Sub
        ''[------------------------------------------------------------------------]'
        Public Sub SetDirty()
            mVar_DirtyBARCODE = True
            mVar_DirtySIZE = True
            mVar_DirtyCOLOR = True
            mVar_DirtyBARDESCR = True
            mVar_DirtySLSQTY = True
            mVar_DirtyDISCACRAMOUNT = True
            mVar_DirtySLSTOTAMT = True
            mVar_DirtySLSPRICE = True
            mVar_DirtySLSDISC = True
        End Sub

    End Class
End Namespace